package com.example.petcare.controller.admin;


import com.example.petcare.pojo.*;
import com.example.petcare.service.OrderService;
import com.example.petcare.service.PetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")//标记为控制器类,并且返回json数据
@RequestMapping("/admin/service")//请求路径
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderservice;

    @Autowired
    private PetService petService;

    // 查询托管需求列表（条件分页查询）
    @GetMapping
    public Result<PageBean<HostDemand>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) Integer orderStatus)
    {

        PageBean<HostDemand> pb= orderservice.list(pageNum, pageSize,status,orderStatus);
        return Result.success(pb);

    }


    // 接单，更新订单状态（status）
    @PutMapping("/accept")
    public Result updateStatus(@RequestParam("hostId") Integer hostId) {
        orderservice.updateStatus(hostId);
        return Result.success();

    }

    // 完成订单，更新订单状态（orderStatus）
    @PutMapping("/complete")
    public Result updateOrderStatus(@RequestParam("hostId") Integer hostId) {
        orderservice.updateOrderStatus(hostId);
        return Result.success();

    }

    // 拒绝订单，更新订单状态（rejectStatus）
    @PutMapping("/reject")
    public Result updateRejectStatus(@RequestParam("hostId") Integer hostId) {
        orderservice.updateRejectStatus(hostId);
        return Result.success();

    }

    // 查看订单宠物信息
    @GetMapping("/pet")
    public Result<Pet> detailPet(Integer petId) {
        Pet pet = petService.findById(petId);
        return Result.success(pet);
    }


    // 查询是否有新订单
    @GetMapping("/new")
    public Result<Integer> hasNewOrder() {
        Integer hasNewOrder = orderservice.hasNewOrder();
        return Result.success(hasNewOrder);
    }


    // 查询用户信息
    @GetMapping("/user")
    public Result<User> userInfo(@RequestParam("hostId") Integer hostId) {
        User user = orderservice.userInfo(hostId);
        return Result.success(user);
    }

}
